<?php
!defined('IN_APP') && exit('Access Denied');

class admin_eventcontrol extends controlbase {


    function ondefault($message='') {
        if(empty($message)) unset($message);
        $eventlist=$this('event')->get_list();
        include template('eventlist');
    }
 

    function onremove() {
        if(isset($this->post['id'])) {
            $ids = $this->post['id'];
            array_walk($ids ,function(&$item){$item = intval($item);});//需要把id转换为int类型
            $this('event')->remove($ids);
		   $this->ondefault('删除成功！');
        }
    }

    function onadd() {
        if(isset($this->post['submit'])) {
	        $event['title'] = $this->post['title'];
			$event['poster'] = getfirstimg($this->post['detail']);
			$event['location'] = $this->post['location'];
			$event['uid'] = $this->user['uid'];
			$event['username'] = $this->user['username'];
			$event['starttime'] = strtotime($this->post['starttime']);
			$event['endtime'] = strtotime($this->post['endtime']);
			//$event['gender'] = '男女不限';
			$event['membernum'] = $this->post['membernum'];
			$event['cost'] = intval($this->post['cost']);
			$event['detail'] = $this->post['detail'];
			$id=$this('event')->add($event);
			$this->ondefault('活动发布成功!');
			exit;
        }
        include template('addevent');
    }

    function onedit() {
        $id = intval($this->get['id']);
        if(isset($this->post['submit'])) {
            $event['title'] = $this->post['title'];
			$event['poster'] = getfirstimg($this->post['detail']);
			$event['location'] = $this->post['location'];
			$event['starttime'] = strtotime($this->post['starttime']);
			$event['endtime'] = strtotime($this->post['endtime']);
			$event['membernum'] = intval($this->post['membernum']);
			$event['cost'] = intval($this->post['cost']);
			$event['detail'] = $this->post['detail'];
            $this('event')->update($id ,$event);
			$this->ondefault('活动编辑成功!');
			exit;
        }
        $event = $this('event')->get_by_id($id);
        include template('editevent');
    }
 
}
